<?php

// +----------------------------------------------------------------------
// | Copyright (c) 2020 All rights reserved.
// +----------------------------------------------------------------------
// | User: Simony <1362229026@qq.com>
// | wechat: Shen86579595
// +----------------------------------------------------------------------
namespace app\mobileapp\controller;


class Other extends Base
{

    /**
     * User: Simony
     * Function:内容分类列表（交友对象）
     */
    public function getContentCategoryList()
    {
        //model
        $contentCategory = model('common/content/Category');
        $list = $contentCategory->getList(['hide' => 0], 0, 'id, name, icon', 'order desc');
        $this->api_ajaxReturn(SUCCESS, '获取成功', $list);
    }

    /**
     * User: Simony
     * Function:标签列表
     */
    public function getLableList()
    {
        //params
        $type = input('type/d', -1);

        $where = ['is_hide' => 0];

        if ($type > 0) $where['type'] = $type;

        $labelModel = model('common/member/Label');
        $list = $labelModel->getList($where, 0, 'id,name', 'sort desc');
        $this->api_ajaxReturn(SUCCESS, '获取成功', $list);
    }
    /**
     * User: Simony
     * Function:省市区类别
     * @apiSuccess {Object} data  返回数据 {"A": [
     * {
     * "first_char": "A",
     * "id": 43,
     * "name": "澳門新城"
     * },
     * {
     * "first_char": "A",
     * "id": 91,
     * "name": "阿克苏地区"
     * }
     * ]}
     */
    public function area()
    {
        $type = input('post.type', 2);
        $name = input('post.name/s', '');


        $areaModel = model('common/area/Area');

        $where = [['dept', 'eq', $type], ['is_show', 'eq', 1]];
        if (!empty($name)) $where[] = ['name', 'like', '%' . $name . '%'];
        $area_list = $areaModel->getList($where, 0, 'first_char,id,name,is_hot,pid', 'first_char asc');


        $list = [];
        foreach ($area_list as $v) {
            $list[$v['first_char']][] = $v;
        }

        $hot_where = ['dept' => $type, 'is_show' => 1, 'is_hot' => 1];
        $hot_list = $areaModel->getList($hot_where, 0, 'first_char,id,name,is_hot,pid', 'first_char asc');


        $data = [
            'list' => $list,
            'hot_list' => $hot_list,
        ];
        $this->api_ajaxReturn(SUCCESS, '获取列表成功', $data);

    }

    /**
     * User: Simony
     * Function:当前城市
     */
    public function getCurrentCity()
    {
        //params
        $latitude = input('post.latitude', 23.13591);
        $longitude = input('post.longitude', 113.27811);
        //model
        $areaModel = model('common/area/Area');
        $current_city = $areaModel->getCityInfoByLatLong($latitude, $longitude);

        $this->api_ajaxReturn(SUCCESS, '获取列表成功', $current_city);
    }


    /**
     * User: Simony
     * Function:时间类型列表
     */
    public function getDateTypeList()
    {
        $choose_list = config('app.choose_list');

        $data = [];
        foreach ($choose_list as $k => $v) {
            $v['date_type'] = $k;
            $data[] = $v;
        }

        $this->api_ajaxReturn(SUCCESS, '获取成功', $data);
    }


    /**
     * User: Simony
     * Function: app配置
     */
    public function appConfig()
    {
        $apple = sysConfig('apple');
        $apple_status = $apple['status'] ?? 0;
        $platform = sysConfig('platform');
        $data = [
            'apple' => [
                'apple_status' => intval($apple_status),
            ],
            'app' => [
                'apple_version' => $platform['apple_version'] ?? 0,
                'apple_download' => $platform['apple_download'] ?? 0,
                'android_version' => $platform['android_version'] ?? 0,
                'android_download' => $platform['android_download'] ?? 0,
            ],
        ];
        $this->api_ajaxReturn(SUCCESS, '获取成功', $data);
    }

}